package product.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Blob;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.Hibernate;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import product.dao.BuildingLockEquipmentDao;
import product.dao.BuildingTalkEquipmentDao;
import product.dao.ControlDiskVideoDao;
import product.dao.VideoMatrixDao;
import product.dao.VideoMonitorDao;
import product.dao.VidiconDao;
import product.dao.YuntaiDao;
import product.model.BuildingLockEquipment;
import product.model.BuildingTalkEquipment;
import product.model.ControlDiskVideo;
import product.model.VideoMatrix;
import product.model.VideoMonitor;
import product.model.Vidicon;
import product.model.Yuntai;
import util.dao.Pagination;

import com.opensymphony.xwork2.ActionSupport;

public class ProductAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Long id;
	
	private BuildingLockEquipment buildingLockEquipment;
	
	private BuildingTalkEquipment buildingTalkEquipment;
	
	private ControlDiskVideo controlDiskVideo;
	
	private VideoMatrix videoMatrix;
	
	private VideoMonitor videoMonitor;
	
	private Vidicon vidicon;
	
	private Yuntai yuntai;
	
	private BuildingLockEquipmentDao buildingLockEquipmentDao;
	
	private BuildingTalkEquipmentDao buildingTalkEquipmentDao;
	
	private ControlDiskVideoDao controlDiskVideoDao;
	
	private VideoMatrixDao videoMatrixDao;
	
	private VideoMonitorDao videoMonitorDao;
	
	private VidiconDao vidiconDao;
	
	private YuntaiDao yuntaiDao;
	
	private List<BuildingLockEquipment> buildingLockEquipmentList = new ArrayList<BuildingLockEquipment>();
	
	private List<BuildingTalkEquipment> buildingTalkEquipmentList = new ArrayList<BuildingTalkEquipment>();
	
	private List<ControlDiskVideo> controlDiskVideoList = new ArrayList<ControlDiskVideo>();
	
	private List<VideoMatrix> videoMatrixList = new ArrayList<VideoMatrix>();
	
	private List<VideoMonitor> videoMonitorList = new ArrayList<VideoMonitor>();
	
	private List<Vidicon> vidiconList = new ArrayList<Vidicon>();
	
	private List<Yuntai> yuntaiList = new ArrayList<Yuntai>();
	
	private InputStream inputStream;
	
	private Pagination<Yuntai> paginationYuntai; 
	
	private Pagination<Vidicon> paginationVidicon ;
	
	private Pagination<VideoMonitor> paginationVideoMonitor ;
	
	private Pagination<ControlDiskVideo> paginationControlDiskVideo ;
	
	private Pagination<VideoMatrix> paginationVideoMatrix ;
	
	private Pagination<BuildingTalkEquipment> paginationBuildingTalkEquipment ;
	
	private Pagination<BuildingLockEquipment> paginationBuildingLockEquipment ; 
	
	private File photo;
	
	private List list = new ArrayList();
	
	private Blob photos;
	
	public Blob getPhotos() {
		return photos;
	}

	public void setPhotos(Blob photos) {
		this.photos = photos;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public Pagination<ControlDiskVideo> getPaginationControlDiskVideo() {
		return paginationControlDiskVideo;
	}

	public void setPaginationControlDiskVideo(
			Pagination<ControlDiskVideo> paginationControlDiskVideo) {
		this.paginationControlDiskVideo = paginationControlDiskVideo;
	}

	public Pagination<Yuntai> getPaginationYuntai() {
		return paginationYuntai;
	}

	public void setPaginationYuntai(Pagination<Yuntai> paginationYuntai) {
		this.paginationYuntai = paginationYuntai;
	}

	public Pagination<Vidicon> getPaginationVidicon() {
		return paginationVidicon;
	}

	public void setPaginationVidicon(Pagination<Vidicon> paginationVidicon) {
		this.paginationVidicon = paginationVidicon;
	}

	public Pagination<VideoMonitor> getPaginationVideoMonitor() {
		return paginationVideoMonitor;
	}

	public void setPaginationVideoMonitor(
			Pagination<VideoMonitor> paginationVideoMonitor) {
		this.paginationVideoMonitor = paginationVideoMonitor;
	}

	public Pagination<VideoMatrix> getPaginationVideoMatrix() {
		return paginationVideoMatrix;
	}

	public void setPaginationVideoMatrix(
			Pagination<VideoMatrix> paginationVideoMatrix) {
		this.paginationVideoMatrix = paginationVideoMatrix;
	}

	public Pagination<BuildingTalkEquipment> getPaginationBuildingTalkEquipment() {
		return paginationBuildingTalkEquipment;
	}

	public void setPaginationBuildingTalkEquipment(
			Pagination<BuildingTalkEquipment> paginationBuildingTalkEquipment) {
		this.paginationBuildingTalkEquipment = paginationBuildingTalkEquipment;
	}

	public Pagination<BuildingLockEquipment> getPaginationBuildingLockEquipment() {
		return paginationBuildingLockEquipment;
	}

	public void setPaginationBuildingLockEquipment(
			Pagination<BuildingLockEquipment> paginationBuildingLockEquipment) {
		this.paginationBuildingLockEquipment = paginationBuildingLockEquipment;
	}

	public File getPhoto() {
		return photo;
	}

	public void setPhoto(File photo) {
		this.photo = photo;
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public List<BuildingLockEquipment> getBuildingLockEquipmentList() {
		return buildingLockEquipmentList;
	}

	public void setBuildingLockEquipmentList(
			List<BuildingLockEquipment> buildingLockEquipmentList) {
		this.buildingLockEquipmentList = buildingLockEquipmentList;
	}

	public List<BuildingTalkEquipment> getBuildingTalkEquipmentList() {
		return buildingTalkEquipmentList;
	}

	public void setBuildingTalkEquipmentList(
			List<BuildingTalkEquipment> buildingTalkEquipmentList) {
		this.buildingTalkEquipmentList = buildingTalkEquipmentList;
	}

	public List<ControlDiskVideo> getControlDiskVideoList() {
		return controlDiskVideoList;
	}

	public void setControlDiskVideoList(List<ControlDiskVideo> controlDiskVideoList) {
		this.controlDiskVideoList = controlDiskVideoList;
	}

	public List<VideoMatrix> getVideoMatrixList() {
		return videoMatrixList;
	}

	public void setVideoMatrixList(List<VideoMatrix> videoMatrixList) {
		this.videoMatrixList = videoMatrixList;
	}

	public List<VideoMonitor> getVideoMonitorList() {
		return videoMonitorList;
	}

	public void setVideoMonitorList(List<VideoMonitor> videoMonitorList) {
		this.videoMonitorList = videoMonitorList;
	}

	public List<Vidicon> getVidiconList() {
		return vidiconList;
	}

	public void setVidiconList(List<Vidicon> vidiconList) {
		this.vidiconList = vidiconList;
	}

	public List<Yuntai> getYuntaiList() {
		return yuntaiList;
	}

	public void setYuntaiList(List<Yuntai> yuntaiList) {
		this.yuntaiList = yuntaiList;
	}

	public BuildingLockEquipment getBuildingLockEquipment() {
		return buildingLockEquipment;
	}

	public void setBuildingLockEquipment(BuildingLockEquipment buildingLockEquipment) {
		this.buildingLockEquipment = buildingLockEquipment;
	}

	public BuildingTalkEquipment getBuildingTalkEquipment() {
		return buildingTalkEquipment;
	}

	public void setBuildingTalkEquipment(BuildingTalkEquipment buildingTalkEquipment) {
		this.buildingTalkEquipment = buildingTalkEquipment;
	}

	public ControlDiskVideo getControlDiskVideo() {
		return controlDiskVideo;
	}

	public void setControlDiskVideo(ControlDiskVideo controlDiskVideo) {
		this.controlDiskVideo = controlDiskVideo;
	}

	public VideoMatrix getVideoMatrix() {
		return videoMatrix;
	}

	public void setVideoMatrix(VideoMatrix videoMatrix) {
		this.videoMatrix = videoMatrix;
	}

	public VideoMonitor getVideoMonitor() {
		return videoMonitor;
	}

	public void setVideoMonitor(VideoMonitor videoMonitor) {
		this.videoMonitor = videoMonitor;
	}

	public Vidicon getVidicon() {
		return vidicon;
	}

	public void setVidicon(Vidicon vidicon) {
		this.vidicon = vidicon;
	}

	public Yuntai getYuntai() {
		return yuntai;
	}

	public void setYuntai(Yuntai yuntai) {
		this.yuntai = yuntai;
	}

	public BuildingLockEquipmentDao getBuildingLockEquipmentDao() {
		return buildingLockEquipmentDao;
	}

	public void setBuildingLockEquipmentDao(
			BuildingLockEquipmentDao buildingLockEquipmentDao) {
		this.buildingLockEquipmentDao = buildingLockEquipmentDao;
	}

	public BuildingTalkEquipmentDao getBuildingTalkEquipmentDao() {
		return buildingTalkEquipmentDao;
	}

	public void setBuildingTalkEquipmentDao(
			BuildingTalkEquipmentDao buildingTalkEquipmentDao) {
		this.buildingTalkEquipmentDao = buildingTalkEquipmentDao;
	}

	public ControlDiskVideoDao getControlDiskVideoDao() {
		return controlDiskVideoDao;
	}

	public void setControlDiskVideoDao(ControlDiskVideoDao controlDiskVideoDao) {
		this.controlDiskVideoDao = controlDiskVideoDao;
	}

	public VideoMatrixDao getVideoMatrixDao() {
		return videoMatrixDao;
	}

	public void setVideoMatrixDao(VideoMatrixDao videoMatrixDao) {
		this.videoMatrixDao = videoMatrixDao;
	}

	public VideoMonitorDao getVideoMonitorDao() {
		return videoMonitorDao;
	}

	public void setVideoMonitorDao(VideoMonitorDao videoMonitorDao) {
		this.videoMonitorDao = videoMonitorDao;
	}

	public VidiconDao getVidiconDao() {
		return vidiconDao;
	}

	public void setVidiconDao(VidiconDao vidiconDao) {
		this.vidiconDao = vidiconDao;
	}

	public YuntaiDao getYuntaiDao() {
		return yuntaiDao;
	}

	public void setYuntaiDao(YuntaiDao yuntaiDao) {
		this.yuntaiDao = yuntaiDao;
	}

	@Transactional(propagation=Propagation.REQUIRED)
	public String toProduct(){
		buildingLockEquipmentList = buildingLockEquipmentDao.findAll();
		buildingTalkEquipmentList = buildingTalkEquipmentDao.findAll();
		controlDiskVideoList = controlDiskVideoDao.findAll();
		videoMatrixList = videoMatrixDao.findAll();
		videoMonitorList = videoMonitorDao.findAll();
		vidiconList = vidiconDao.findAll();
		yuntaiList = yuntaiDao.findAll();
		
		
		list.addAll(buildingLockEquipmentList);
		list.addAll(buildingTalkEquipmentList);
		list.addAll(controlDiskVideoList);
		list.addAll(videoMatrixList);
		list.addAll(videoMonitorList);
		list.addAll(vidiconList);
		list.addAll(yuntaiList);
		
		System.out.println(list);
		return SUCCESS;
	}
	
	public String toProductAdmin(){
		buildingLockEquipmentList = buildingLockEquipmentDao.findAll();
		buildingTalkEquipmentList = buildingTalkEquipmentDao.findAll();
		controlDiskVideoList = controlDiskVideoDao.findAll();
		videoMatrixList = videoMatrixDao.findAll();
		videoMonitorList = videoMonitorDao.findAll();
		vidiconList = vidiconDao.findAll();
		yuntaiList = yuntaiDao.findAll();
		return SUCCESS;
	}
	
	public String toAddYuntai(){
		if(paginationYuntai==null){
			paginationYuntai = new Pagination<Yuntai>();
		}
		if(paginationYuntai.getNo()<=0){
			paginationYuntai.setNo(1);
		}
		paginationYuntai.setSize(5);
		yuntaiDao.browse(paginationYuntai);
		yuntaiList = paginationYuntai.getResults();
		return SUCCESS;
	}
	
	public String addYuntai() throws Exception{
		yuntai.setPhoto(Hibernate.createBlob(new FileInputStream(photo)));
		yuntaiDao.saveOrUpdate(yuntai);
		return SUCCESS;
	}
	
	public String toAddVidicon(){
		if(paginationVidicon==null){
			paginationVidicon = new Pagination<Vidicon>();
		}
		if(paginationVidicon.getNo()<=0){
			paginationVidicon.setNo(1);
		}
		paginationVidicon.setSize(5);
		vidiconDao.browse(paginationVidicon);
		vidiconList = paginationVidicon.getResults();
		return SUCCESS;
	}
	
	public String addVidicon()throws Exception{
		vidicon.setPhoto(Hibernate.createBlob(new FileInputStream(photo)));
		vidiconDao.saveOrUpdate(vidicon);
		return SUCCESS;
	}
	
	public String toAddVideoMonitor(){
		if(paginationVideoMonitor==null){
			paginationVideoMonitor = new Pagination<VideoMonitor>();
		}
		if(paginationVideoMonitor.getNo()<=0){
			paginationVideoMonitor.setNo(1);
		}
		paginationVideoMonitor.setSize(5);
		videoMonitorDao.browse(paginationVideoMonitor);
		videoMonitorList = paginationVideoMonitor.getResults();
		return SUCCESS;
	}
	
	public String addVideoMonitor() throws Exception{
		videoMonitor.setPhoto(Hibernate.createBlob(new FileInputStream(photo)));
		videoMonitorDao.saveOrUpdate(videoMonitor);
		return SUCCESS;
	}
	
	public String toAddVideoMatrix(){
		if(paginationVideoMatrix==null){
			paginationVideoMatrix = new Pagination<VideoMatrix>();
		}
		if(paginationVideoMatrix.getNo()<=0){
			paginationVideoMatrix.setNo(1);
		}
		paginationVideoMatrix.setSize(5);
		videoMatrixDao.browse(paginationVideoMatrix);
		videoMatrixList = paginationVideoMatrix.getResults();
		return SUCCESS;
	}
	
	public String addVideoMatrix() throws Exception{
		videoMatrix.setPhoto(Hibernate.createBlob(new FileInputStream(photo)));
		videoMatrixDao.saveOrUpdate(videoMatrix);
		return SUCCESS;
	}
	
	public String toAddControlDiskVideo(){
		if(paginationControlDiskVideo==null){
			paginationControlDiskVideo = new Pagination<ControlDiskVideo>();
		}
		if(paginationControlDiskVideo.getNo()<=0){
			paginationControlDiskVideo.setNo(1);
		}
		paginationControlDiskVideo.setSize(5);
		controlDiskVideoDao.browse(paginationControlDiskVideo);
		controlDiskVideoList = paginationControlDiskVideo.getResults();
		return SUCCESS;
	}
	
	public String addControlDiskVideo() throws Exception{
		controlDiskVideo.setPhoto(Hibernate.createBlob(new FileInputStream(photo)));
		controlDiskVideoDao.saveOrUpdate(controlDiskVideo);
		return SUCCESS;
	}
	
	public String toAddBuildingTalkEquipment(){
		if(paginationBuildingTalkEquipment==null){
			paginationBuildingTalkEquipment = new Pagination<BuildingTalkEquipment>();
		}
		if(paginationBuildingTalkEquipment.getNo()<=0){
			paginationBuildingTalkEquipment.setNo(1);
		}
		paginationBuildingTalkEquipment.setSize(5);
		buildingTalkEquipmentDao.browse(paginationBuildingTalkEquipment);
		buildingTalkEquipmentList = paginationBuildingTalkEquipment.getResults();
		return SUCCESS;
	}
	
	public String addBuildingTalkEquipment() throws Exception{
		buildingTalkEquipment.setPhoto(Hibernate.createBlob(new FileInputStream(photo)));
		buildingTalkEquipmentDao.saveOrUpdate(buildingTalkEquipment);
		return SUCCESS;
	}
	
	public String toAddBuildingLockEquipment(){
		if(paginationBuildingLockEquipment==null){
			paginationBuildingLockEquipment = new Pagination<BuildingLockEquipment>();
		}
		if(paginationBuildingLockEquipment.getNo()<=0){
			paginationBuildingLockEquipment.setNo(1);
		}
		paginationBuildingLockEquipment.setSize(5);
		buildingLockEquipmentDao.browse(paginationBuildingLockEquipment);
		buildingLockEquipmentList = paginationBuildingLockEquipment.getResults();
		return SUCCESS;
	}
	
	public String addBuildingLockEquipment() throws Exception{
		buildingLockEquipment.setPhoto(Hibernate.createBlob(new FileInputStream(photo)));
		buildingLockEquipmentDao.saveOrUpdate(buildingLockEquipment);
		return SUCCESS;
	}
	
	public String updateBuildingLockEquipment(){
		buildingLockEquipment = buildingLockEquipmentDao.findById(buildingLockEquipment.getId());
		id = buildingLockEquipment.getId();
		return SUCCESS;
	}
	
	public String deleteBuildingLockEquipment(){
		buildingLockEquipmentDao.delete(buildingLockEquipmentDao.findById(buildingLockEquipment.getId()));
		return SUCCESS;
	}
	
	public String updateBuildingTalkEquipment(){
		buildingTalkEquipment = buildingTalkEquipmentDao.findById(buildingTalkEquipment.getId());
		id = buildingTalkEquipment.getId();
		return SUCCESS;
	}
	
	public String deleteBuildingTalkEquipment(){
		buildingTalkEquipmentDao.delete(buildingTalkEquipmentDao.findById(buildingTalkEquipment.getId()));
		return SUCCESS;
	}
	
	public String updateControlDiskVideo(){
		controlDiskVideo = controlDiskVideoDao.findById(controlDiskVideo.getId());
		id = controlDiskVideo.getId();
		return SUCCESS;
	}
	
	public String deleteControlDiskVideo(){
		controlDiskVideoDao.delete(controlDiskVideoDao.findById(controlDiskVideo.getId()));
		return SUCCESS;
	}
	
	public String updateVideoMatrix(){
		videoMatrix = videoMatrixDao.findById(videoMatrix.getId());
		id = videoMatrix.getId();
		return SUCCESS;
	}
	
	public String deleteVideoMatrix(){
		videoMatrixDao.delete(videoMatrixDao.findById(videoMatrix.getId()));
		return SUCCESS;
	}
	
	public String updateVideoMonitor(){
		videoMonitor = videoMonitorDao.findById(videoMonitor.getId());
		id = videoMonitor.getId();
		return SUCCESS;
	}
	
	public String deleteVideoMonitor(){
		videoMonitorDao.delete(videoMonitorDao.findById(videoMonitor.getId()));
		return SUCCESS;
	}
	
	public String updateVidicon(){
		vidicon = vidiconDao.findById(vidicon.getId());
		id = vidicon.getId();
		return SUCCESS;
	}
	
	public String deleteVidicon(){
		vidiconDao.delete(vidiconDao.findById(vidicon.getId()));
		return SUCCESS;
	}
	
	public String updateYuntai(){
		yuntai = yuntaiDao.findById(yuntai.getId());
		id = yuntai.getId();
		return SUCCESS;
	}
	
	public String deleteYuntai(){
		yuntaiDao.delete(yuntaiDao.findById(yuntai.getId()));
		return SUCCESS;
	}
	
	public String toShowBuildingLockEquipment(){
		buildingLockEquipment = buildingLockEquipmentDao.findById(buildingLockEquipment.getId());
		return SUCCESS;
	}
	
	public String buildingLockEquipmentPhoto() throws Exception{
		buildingLockEquipment = buildingLockEquipmentDao.findById(buildingLockEquipment.getId());
		inputStream=buildingLockEquipment.getPhoto().getBinaryStream();
		return SUCCESS;
	}
	
	public String toShowBuildingTalkEquipment(){
		buildingTalkEquipment = buildingTalkEquipmentDao.findById(buildingTalkEquipment.getId());
		return SUCCESS;
	}
	
	public String buildingTalkEquipmentPhoto() throws Exception{
		buildingTalkEquipment = buildingTalkEquipmentDao.findById(buildingTalkEquipment.getId());
		inputStream=buildingTalkEquipment.getPhoto().getBinaryStream();
		return SUCCESS;
	}
	
	public String toShowControlDiskVideo(){
		controlDiskVideo = controlDiskVideoDao.findById(controlDiskVideo.getId());
		return SUCCESS;
	}
	
	public String controlDiskVideoPhoto() throws Exception{
		controlDiskVideo = controlDiskVideoDao.findById(controlDiskVideo.getId());
		inputStream=controlDiskVideo.getPhoto().getBinaryStream();
		return SUCCESS;
	}
	
	public String toShowVideoMatrix(){
		videoMatrix = videoMatrixDao.findById(videoMatrix.getId());
		return SUCCESS;
	}
	
	public String videoMatrixPhoto() throws Exception{
		videoMatrix = videoMatrixDao.findById(videoMatrix.getId());
		inputStream=videoMatrix.getPhoto().getBinaryStream();
		return SUCCESS;
	}
	
	public String toShowVideoMonitor(){
		videoMonitor = videoMonitorDao.findById(videoMonitor.getId());
		return SUCCESS;
	}
	
	public String videoMonitorPhoto() throws Exception{
		videoMonitor = videoMonitorDao.findById(videoMonitor.getId());
		inputStream=videoMonitor.getPhoto().getBinaryStream();
		return SUCCESS;
	}
	
	public String toShowVidicon(){
		vidicon = vidiconDao.findById(vidicon.getId());
		return SUCCESS;
	}
	
	public String vidiconPhoto() throws Exception{
		vidicon = vidiconDao.findById(vidicon.getId());
		inputStream=vidicon.getPhoto().getBinaryStream();
		return SUCCESS;
	}
	
	public String toShowYuntai(){
		yuntai = yuntaiDao.findById(yuntai.getId());
		return SUCCESS;
	}
	
	public String yuntaiPhoto() throws Exception{
		yuntai = yuntaiDao.findById(yuntai.getId());
		inputStream=yuntai.getPhoto().getBinaryStream();
		return SUCCESS;
	}
	public String showPhoto() throws Exception{
		this.inputStream=photos.getBinaryStream();
		return SUCCESS;
	}
}
